<template>
  <div class="ms-list">
    <el-row class="operation">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">
          <icon style="" name="home"></icon>
        </el-breadcrumb-item>
        <el-breadcrumb-item>系统设置</el-breadcrumb-item>
        <el-breadcrumb-item>修改密码</el-breadcrumb-item>
        <el-breadcrumb-item>列表</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>

    <el-form class="element-form" label-width="100px" :model="row.form" ref="formModifyRow">
      <el-form-item label="原密码" prop="oldPassword" :rules="[{required: true, message: '请填写原密码'}]">
        <el-input v-model="row.form.oldPassword" type="password" clearable></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="password" :rules="[{required: true, message: '请填写新密码'}, {minlength: 6}]">
        <el-input v-model="row.form.password" type="password" placeholder="最少6位，建议含字母、数字、特殊字符" clearable></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="confirm" :rules="[{required: true, message: '请填写新密码'}]">
        <el-input v-model="row.form.confirm" type="password" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitRow()">提交</el-button>
        <el-button @click="resetForm('formModifyRow')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import Api from '@/api/customer/password'
  import MsConfirmButton from '@/components/common/ConfirmButton.vue'
  import { FormArgument } from '@/models/customer/password'

  export default {
    components: {
      MsConfirmButton
    },
    data () {
      return {
        row: {
          form: new FormArgument()
        }
      }
    },
    methods: {
      submitRow () {
        this.$refs['formModifyRow'].validate((valid) => {
          if (valid) {
            Api.modify({form: this.row.form}, response => {
              let status = response.status || 0
              let body = response.data || {}
              if (status >= 200 && status <= 204) {
                this.$message.success('修改成功')
                this.resetForm('formModifyRow')
              } else {
                this.$message.error(body.error || '修改失败')
              }
            })
          } else {
            return false
          }
        })
      },
      resetForm (formName) {
        this.$refs[formName].resetFields()
      },
      showSlide (ref) {
        this.$refs[ref].show()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .ms-list {
    padding: 24px;
  }

  .element-form {
    width: 460px;
  }
</style>
